const express=require('express');
const router=express.Router();
const AboutController=require('../controllers/aboutController.js')
const path=require('path');

/* 完成图片上传功能 */
const multer=require('multer');
// const upload=multer({desk:path.join(__dirname,'../public/uploads')})
const storage=multer.diskStorage({
    destination:function (req,file,cb) {
        cb(null,path.join(__dirname,'../public/uploads'))
    },
    filename:function (req,file,cb) {
        const uniqueSuffix=Date.now()+'-'+Math.round(Math
            .random()*1E9);
        // path.extname(file.originalname) 可以获取文件的扩展名
        cb(null,file.fieldname+'-'+uniqueSuffix+path.extname(file.originalname));
    }
})
const upload=multer({storage:storage});

//1、关于我们分类的添加
router.get('/category/add',AboutController.getCategoryAdd);
// 收集数据，然后定义表的模型，入库
router.post('/category/store', AboutController.AddCategoryPutInStore);
//2、关于我们分类的展示
router.get('/category/list', AboutController.getCategoryList);
// 3、通过路由参数进行删除
router.get('/category/delete/:id', AboutController.getCategoryDel);
// 4、编辑 ，更新数据
router.get('/category/edt/:id',AboutController.getCategoryEdt);

router.post('/category/edtstore',AboutController.EdtCategoryPutInStore);

// 5、关于我们信息列表
router.get('/list',AboutController.getAboutList);
// 6、关于我们信息添加
router.get('/add', AboutController.getAboutAdd);
//入库
router.post('/store', upload.single('pic'),AboutController.AddPutInStore);
// 7、通过查找参数进行删除
router.get('/delete', AboutController.getAboutDel);
// 8编辑
router.get('/edt',AboutController.getAboutEdt);
//入库
router.post('/edtstore',upload.single('pic'),AboutController.EdtPutInStore);
module.exports=router;